<template>
  <div :class="className">
    <!-- style -->
    <div v-html="css"></div>

    <!--带货直播静态-->
    <div v-if="datas.preview_color">
      <div id="live">
        <div class="nav nav-bgimage" v-if="datas.tab_list && datas.tab_list.length > 0">
          <div class="nav-li" :class="{ 'nav-selected': datas.choose_tab == '0' }" v-if="datas.tab_list.indexOf('0') > -1">
            <div class=" nav-lis">
              全部
            </div>
          </div>
          <div class="nav-li" :class="{ 'nav-selected': datas.choose_tab == '1' }" v-if="datas.tab_list.indexOf('1') > -1">
            <div class="nav-lis">
              推荐
            </div>
          </div>
          <div class="nav-li" :class="{ 'nav-selected': datas.choose_tab == '2' }" v-if="datas.tab_list.indexOf('2') > -1">
            <div class="nav-lis">
              直播中
            </div>
          </div>
          <div class="nav-li" :class="{ 'nav-selected': datas.choose_tab == '3' }" v-if="datas.tab_list.indexOf('3') > -1">
            <div class="nav-lis">
              预告
            </div>
          </div>
          <div class="nav-li" :class="{ 'nav-selected': datas.choose_tab == '4' }" v-if="datas.tab_list.indexOf('4') > -1">
            <div class="nav-lis">
              精彩回放
            </div>
          </div>
        </div>
        <div class="live-list">
          <div class="lis" v-for="item in 2">
            <div class="image">
              <img :src="good_img" alt="" />
            </div>
            <div class="label">
              <div class="living">直播中</div>
              <div class="num">4555人观看</div>
              <div class="icon">
                <i class="iconfont icon-zb_goods1"></i>
                <div class="icon-num">56</div>
              </div>
            </div>
            <div class="title">
              带货直播标题---带货直播标题---带货直播标题
            </div>
            <div class="name">
              <img :src="img" alt="" style="" />
              <span>时尚穿搭博主</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// 自定义样式
const css = function() {
	if(this.datas.preview_color) {
		const {
			preview_color,
			tab_bg_color,
			tab_color,
			tab_active_color,
		} = this.datas;

		return `
        .component-${this.id} .live-list {
            background-color: ${preview_color};
        }

        .component-${this.id} .nav {
            background-color: ${tab_bg_color};
        }

        .component-${this.id} .nav .nav-li {
            color: ${tab_color};
        }

        .component-${this.id} .nav .nav-li.nav-selected {
            border-bottom: solid  2px ${tab_active_color};
            color: ${tab_active_color};
        }

    `;
  }
};

export default {
  data() {
    return {
	    img: require('../../../resource/images/image.png'),
	    good_img: require('../../../resource/images/default-goods.png'),
    };
  },
  props: ["id", "datas", "styles"],
  computed: {
    css() {
      return "<style>" + css.call(this) + "</style>";
    },
    className() {
      const name = ["component-wrapper", `component-${this.id}`];
      return name;
    },
  },

  methods: {
  },

  mounted() {
    this.$emit("loaded");
  },
};
</script>

<style lang="less" scoped>
// 默认
.component-wrapper {
  width: 375px;
}
#live {
  .nav {
    display: flex;
    align-items: center;
    height: 40px;
    white-space: nowrap;
    flex-wrap: nowrap;
    box-sizing: content-box;
    .nav-li {
      flex: 1;
      min-width: 20%;
      text-align: center;
      .nav-lis {
        display: inline-block;
        line-height: 40px;
      }
    }
    .nav-selected {
      /*border-bottom: 2px solid #333;*/
      // font-weight: 600;
    }
  }

  .scroll {
    overflow-x: scroll;
  }
  .live-list {
    display: flex;
    flex-wrap: wrap;
    padding: 5px;
    .lis {
      width: 172px;
      margin: 0 5px;
      position: relative;
      .label {
        position: absolute;
        top: 0;
        padding: 7px 0 0 7px;
        font-size: 12px;
        display: flex;
        color: #fff;
        width: 100%;
        .living {
          overflow: hidden;
          background: #ff2c29;
          border-radius: 3.5px;
          padding: 2px 5px;
        }
        .num {
          max-width: 98px;
          margin-left: 2px;
          padding: 2px 5px;
          background: rgba(0, 0, 0, 0.15);
          border-radius: 3px;
          overflow: hidden;
          white-space: nowrap;
        }
        .icon {
          text-align: right;
          flex:1;
          color: #ffa303;
          position: relative;
          margin-right: 10px;
          .icon-num {
            position: absolute;
            top: 5px;
            right: -7px;
            background: #fff;
            border-radius: 10px;
            color: #f00;
            font-weight: 600;
            display: inline-block;
            padding: 0px 2px;
            margin: 0;
            line-height: 12px;
          }
        }
        .lived{
          width: 35px;
          overflow: hidden;
          background: #999999;
          border-radius: 3.5px;
          padding: 2px 5px;
        }
      }
      .image {
        border-radius: 12.5px;
        height: 220px;
        width: 100%;
        img {
          border-radius: 12px;
          width: 100%;
        }
      }
      .title {
        position: absolute;
        bottom: 42px;
        height: 32px;
        line-height: 16px;
        padding: 0 7px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        color: #fff;
      }
      .name {
        height: 24px;
        line-height: 24px;
        color: #000;
        padding: 0 7px;
        margin-top: 7px;
        img {
          width: 30px;
          height: 30px;
          border-radius: 50%;
          border: 2px solid #fff;
          position: relative;
          bottom: 5px;
        }
      }
    }
  }
}
</style>
